package com.sxjh.controller.ny;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.sxjh.common.BaseController;
import com.sxjh.common.Result;
import com.sxjh.entity.Dictionary;
import com.sxjh.service.DictionaryService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * <p>
 * 数据字典 前端控制器
 * </p>
 *
 * @author zixin
 * @since 2023-06-25
 */
@RestController
@RequestMapping("/dictionary")
@Api(tags = "数据字典")
public class DictionaryController extends BaseController {


    @Autowired
    private DictionaryService dictionaryService;


    @PostMapping(value = "/addOrUpdate")
    public Result<Object> addOrUpdate(@Valid @RequestBody Dictionary req){
        LambdaQueryWrapper<Dictionary> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(Dictionary::getName,req.getName());
        if (dictionaryService.saveOrUpdate(req,wrapper)) {
            return Result.ok("");
        }
        return Result.err();
    }


}

